package com.atguigu.core.handler;


import com.atguigu.core.bean.R;
import com.atguigu.core.enumcode.BizResultCodeEnum;
import com.atguigu.core.exception.BizException;
import com.atguigu.core.util.ExceptionUtil;
import jakarta.annotation.Priority;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Priority(1)

public class ExceptionAdviceHandler {

    @ExceptionHandler(value = BizException.class)
    public Object handleException(BizException e) {

        return R.failure(e.getCode(), e.getMessage());


    }

    @ExceptionHandler(Exception.class)
    public @ResponseBody
    Object handleException(Exception ex) {
        ExceptionUtil.logExceptionInfo(ex);
        return R.failure(BizResultCodeEnum.UNKNOW_ERROR.getCode(), BizResultCodeEnum.UNKNOW_ERROR.getDescription());
    }

}
